const {SyncLoopHook} = require('tapable')

let hook = new SyncLoopHook(['name', 'age'])

let count1 = 0
let count2 = 0
let count3 = 0

// 定义
hook.tap('fn1', function (name, age) {
    console.log('fn1--->', name, age)
    if (++count1 === 1) {
        count1 = 0
        // 返回undefined退出loop
        return undefined
    }
    return true
})

// 返回undefined不会熔断
hook.tap('fn2', function (name, age) {
    console.log('fn2--->', name, age)
    // 不满足条件,从头开始(fn1)执行
    // count++ -> count+=1
    if (++count2 === 2) {
        count2 = 0
        return undefined
    }
    return true
})

// 返回!undefined会熔断
hook.tap('fn3', function (name, age) {
    console.log('fn3--->', name, age)
    if (++count3 === 3) {
        count3 = 0
        return undefined
    }
    return true
})

hook.call('foo', 33)